package com.wx.wechat.request;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

import static com.wx.wechat.constant.WechatParameterName.WechatRequest.*;

/**
 * @author wx
 * @Description: 退款请求对象
 * @date 2018/11/5 000518:45
 */
@Data
public class Refund {
    /**
     * 商户订单号
     */
    private String outTradeNo;
    /**
     * 商户退款单号
     */
    private String outRefundNo;
    /**
     * 订单金额(单位分)
     */
    private int totalFee;
    /**
     * 退款金额(单位分)
     */
    private int refundFee;

    /**
     * 初始化请求map参数
     */
    public Map<String, String> initRequestParameter(Map<String, String> requestParameterMap) {
        if (StringUtils.isNotBlank(getOutRefundNo())) {
            requestParameterMap.put(REQUEST_OUT_REFUND_NO, getOutRefundNo());
        }
        if (StringUtils.isNotBlank(getOutTradeNo())) {
            requestParameterMap.put(REQUEST_OUT_TRADE_NO, getOutTradeNo());
        }
        if (getTotalFee() > 0) {
            requestParameterMap.put(REQUEST_TOTAL_FEE, String.valueOf(getTotalFee()));
        }
        if (getRefundFee() > 0) {
            requestParameterMap.put(REQUEST_REFUND_FEE, String.valueOf(getRefundFee()));
        }
        return requestParameterMap;
    }
}
